<?php

namespace App\Http\Controllers\H5;
use App\Exceptions\BusinessException;
use App\Http\Controllers\BaseController;
use App\Params\H5\AfterSalesApplyParams;
use App\Params\H5\AfterSalesListParams;
use App\Services\AfterSales\AfterSalesService;
use App\Traits\VerifyRequestParam;

/**
 * 售后相关控制器
 *
 * @package App\Http\Controllers\H5
 * @author WangBin
 * @date 2021-06/11
 */
class AfterSalesController extends BaseController
{
    use VerifyRequestParam;

    /**
     * 获取售后商品信息
     *
     * @throws
     * @return
     */
    public function getGoods()
    {
        $orderId = $this->verifyInteger('order_id');
        $productId = $this->verifyInteger('product_id');
        $ret = AfterSalesService::getInstance()->getGoods($orderId, $productId);
        return $this->success($ret);
    }

    /**
     * 申请售后
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function apply()
    {
        $param = AfterSalesApplyParams::create();
        AfterSalesService::getInstance()->apply($param);
        return $this->success();
    }

    /**
     * 获取客户售后申请列表
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function getList()
    {
        $param = AfterSalesListParams::create();
        $list = AfterSalesService::getInstance()->getH5List($param);
        return $this->success($list);
    }

    /**
     * 获取售后单详情
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws BusinessException
     */
    public function get()
    {
        $applyId = $this->verifyInteger('apply_id');
        $customerId = $this->verifyInteger('customer_id');
        $ret = AfterSalesService::getInstance()->getH5Detail($applyId, $customerId);
        return $this->success($ret);
    }
}
